package com.facotry.controller;

import com.facotry.entity.ProduceOrder;
import com.facotry.entity.ProducePlan;
import com.facotry.service.ProducePlanService;
import com.facotry.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * ------ 天道酬勤 -------
 *
 * @author ChenZihao
 * @date 2024/7/24
 * @desc --- 代码敲烂 月薪过万 ---
 */

@RestController
@RequestMapping("/producePlan")
public class ProducePlanController {

    @Autowired
    private ProducePlanService producePlanService;

    @GetMapping("/getList")
    public R findAll(@RequestParam HashMap<String, String> map) {
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum, pageSize);
        List<ProducePlan> list = producePlanService.findAll(map);
        PageInfo<ProducePlan> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }


    @PostMapping("/addProducePlan")
    public R addProducePlan(@RequestBody ProducePlan producePlan) {
        boolean isOk = producePlanService.addProducePlan(producePlan);
        return R.ok(isOk);

    }


    @GetMapping("/delBatchPlans")
    public R delBatchPlans(@RequestParam List<String> ids) {
        int i = producePlanService.delBatchPlans(ids);
        if (i > 0) {
            return R.ok();
        }
        return R.fail();
    }


    @GetMapping("/delPlanByNum")
    public R delPlanByNum(String num){
        boolean isOk = producePlanService.delPlanByNum(num);
        return R.ok(isOk);
    }


    @PostMapping("/editPlan")
    public  R editPlan(@RequestBody ProducePlan producePlan){
        System.out.println("producePlan = " + producePlan);
        boolean isOk = producePlanService.editPlan(producePlan);
        return  R.ok(isOk);

    }


    @PostMapping("/editManagePlan")
    public R editManagePlan(@RequestBody ProducePlan producePlan){
        System.out.println("producePlan = " + producePlan);
        boolean isOk = producePlanService.editManagePlan(producePlan);

       return R.ok(isOk);
    }


}
